package sourceagile.webservices.subversion;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jettison.json.JSONArray;

import sourceagile.server.subversionFileRepository.ListSubversionFiles;
import sourceagile.webservices.GetCallback;

@SuppressWarnings("serial")
public class ListSubversionFilesServlet extends HttpServlet {

	// http://localhost:8080/LiveSourceWebServices/ListFilesSubversionService
	// ?repositoryURL=https://tictactoe4j.googlecode.com/svn/trunk
	// &username=null&password=null

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws IOException {

		String repositoryURL = request.getParameter("repositoryURL");

		String username = request.getParameter("username");

		String password = request.getParameter("password");

		JSONArray list = ListSubversionFiles.listEntries(repositoryURL,
				username, password);

		String answer = GetCallback.getCallback(
				request.getParameter("callback"), list.toString());

		response.setContentType("text/javascript");

		response.getWriter().println(answer);
	}
}
